﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;

namespace Muel.TypeScriptFacade.TestPlatform.Services
{
    /// <summary>
    /// Performs arithmetic
    /// </summary>
    [WebService]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    public class Arithmetic : WebService
    {
        [WebMethod]
        [ScriptMethod]
        public int Add(int x, int y)
        {
            return x + y;
        }

        [WebMethod]
        [ScriptMethod]
        public int Sum(int[] values)
        {
            return values.Sum();
        }

        [WebMethod]
        [ScriptMethod]
        public Triplet CreateTriplet(double x, double y, double z)
        {
            return new Triplet()
            {
                First = x,
                Second = y,
                Third = z
            };
        }

        [WebMethod]
        [ScriptMethod]
        public double AddValues(Triplet triplet)
        {
            return triplet.First + triplet.Second + triplet.Third;
        }

        [WebMethod]
        [ScriptMethod]
        public TripletPair JoinTriplets(double leftX, double leftY, double leftZ, double rightX, double rightY, double rightZ)
        {
            return new TripletPair()
            {
                Left = new Triplet()
                {
                    First = leftX,
                    Second = leftY,
                    Third = leftZ,
                },
                Right = new Triplet()
                {
                    First = rightX,
                    Second = rightY,
                    Third = rightZ,
                }
            };
        }

        [WebMethod]
        [ScriptMethod]
        public Triplet SumTriplets(Triplet[] triplets)
        {
            double first = triplets.Sum(t => t.First);
            double second = triplets.Sum(t => t.Second);
            double third = triplets.Sum(t => t.Third);
            return new Triplet()
            {
                First = first,
                Second = second,
                Third = third
            };
        }
    }
}
